home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga Plus 2000 #5
/
Amiga Plus CD - 2000 - No. 5.iso
/
Tools
/
Misc
/
InstallerNG
/
developer
/
gui
/
example
/
igui_InitApp.c
< prev
next >
Wrap
C/C++ Source or Header
|
1999-10-31
|
20KB
|
403 lines
#include "includes.h"
#include "installergui_data.h"
/********************************************************************
*
* DESCRIPTION
*
* allocate memory for the base structure and return it;
* additionally set up the window and, if you want to,
* a gauge for showing the completion of the parsing process
*
* IN: texts - a pointer to an array of localized stringpointers
* (see the gui.h include for the text offsets)
* title - pointer to the window- and screentitle for the
* installer gui
* globalenv - the global installation environment; things
* like "MINUSER", "LOGFILE" etc are stored
* here
*
* OUT: a private pointer to an application structure or NULL
* if something went wrong
*
*/
/********************************************************************
*
* STATIC
*
*/
static void __asm __saveds gui_BTMKDirProceedFun(register __a2 APTR, register __a1 LONG *);
static void __saveds gui_SendCtrlCFun(void);
static void __saveds gui_SendCtrlDFun(void);
static void __saveds gui_SendCtrlEFun(void);
static const struct Hook gui_bt_mkdirproceed_hook = { { NULL, NULL }, (VOID *) gui_BTMKDirProceedFun, NULL, NULL };
static const struct Hook gui_bt_closewin_hook = { { NULL, NULL }, (VOID *) gui_SendCtrlCFun, NULL, NULL };
static const struct Hook gui_bt_proceed_hook = { { NULL, NULL }, (VOID *) gui_SendCtrlDFun, NULL, NULL };
static const struct Hook gui_bt_abort_hook = { { NULL, NULL }, (VOID *) gui_SendCtrlEFun, NULL, NULL };
/********************************************************************
*
* EXTERN
*
*/
/********************************************************************
*
* PUBLIC
*
*/
/********************************************************************
*
* CODE
*
*/
APTR __asm igui_InitApp(register __a0 char **texts,
register __a1 char *title,
register __a2 ULONG *globalenv)
{
#ifdef DEBUG
DEBUG_MAKRO
#endif
{
struct Application *app = NULL;
// since this gui works with MUI, we have to open the muimaster lib here
// (if it's not yet open :-)
if (!MUIMasterBase) { MUIMasterBase = OpenLibrary("muimaster.library", 19); }
if (MUIMasterBase)
{
// allocate memory for the application-structure
if (app = AllocVec(sizeof(struct Application), MEMF_ANY|MEMF_CLEAR))
{
// temporary store the references to different mui-objects, such that
// they can be bind together with hooks later
APTR WI_about, WI_help, WI_aboutmui;
APTR BT_openabout, BT_endabout, BT_openhelp, BT_endhelp, BT_proceed, BT_abort,
BT_mkdir_proceed, BT_mkdir_cancel;
APTR ST_mkdir_name;
APTR CM_mkdir_info;
APTR MN_menu, MN_about, MN_aboutmui, MN_quit;
// keep the arguments
app->app_Texts = texts;
app->app_Title = title;
app->app_GlobalEnv = globalenv;
// initially, no error occured yet
app->app_Error = GUIERROR_NOERROR;
// create the
app->app_Application = ApplicationObject,
MUIA_Application_Title, "InstallerNG",
MUIA_Application_Version, app->app_Title,
MUIA_Application_Copyright, "(c) 1997-1999 by Jens Tröger",
MUIA_Application_Author, "Jens Tröger",
MUIA_Application_Description, "InstallerNG with MUI-GUI",
MUIA_Application_Base, "INSTALLER-NG",
// this gui gets its own menu (not a must)
MUIA_Application_Menustrip, MN_menu = MenustripObject,
MUIA_Family_Child, MenuObject,
MUIA_Menu_Title, app->app_Texts[MENU_PROJECT],
MUIA_Family_Child, MN_about = MenuitemObject,
MUIA_Menuitem_Title, app->app_Texts[MENU_ABOUT],
MUIA_Menuitem_Shortcut, "A",
End,
MUIA_Family_Child, MN_aboutmui = MenuitemObject,
MUIA_Menuitem_Title, app->app_Texts[MENU_ABOUTGUI],
MUIA_Menuitem_Shortcut, "G",
End,
MUIA_Family_Child, MUI_MakeObject(MUIO_Menuitem, NM_BARLABEL, 0, 0, 0),
MUIA_Family_Child, MN_quit = MenuitemObject,
MUIA_Menuitem_Title, app->app_Texts[MENU_QUIT],
MUIA_Menuitem_Shortcut, "Q",
End,
End,
End,
// the window which contains information about the installer itself
SubWindow, WI_about = WindowObject,
MUIA_Window_Title, app->app_Title,
MUIA_Window_ID, MAKE_ID('1', 'W', 'I', 'N'),
WindowContents, GroupObject,
Child, GroupObject,
//MUIA_Frame, MUIV_Frame_Group,
Child, TextObject,
MUIA_Background, MUII_TextBack,
MUIA_Frame, MUIV_Frame_Text,
MUIA_Text_Contents, app->app_Texts[ABOUT],
MUIA_Text_PreParse, "\33c",
End,
Child, BT_endabout = SimpleButton(app->app_Texts[INTERESTING]),
End,
End,
End,
// the help window
SubWindow, WI_help = WindowObject,
MUIA_Window_Title, app->app_Title,
MUIA_Window_ID, MAKE_ID('2', 'W', 'I', 'N'),
WindowContents, GroupObject,
Child, GroupObject,
//MUIA_Frame, MUIV_Frame_Group,
Child, ListviewObject,
MUIA_Listview_Input, FALSE,
MUIA_Listview_List, app->app_HelpText = FloattextObject,
MUIA_Frame, MUIV_Frame_ReadList,
MUIA_Background, MUII_ReadListBack,
MUIA_Floattext_TabSize, 4,
MUIA_Floattext_Justify, TRUE,
End,
End,
Child, BT_endhelp = SimpleButton(app->app_Texts[THANX]),
End,
End,
End,
// information about MUI
SubWindow, WI_aboutmui = AboutmuiObject,
End,
// the Makedir window is required by "AskFile" and "AskDir"
// function to provide tha ability to create a new drawer
SubWindow, app->app_MkdirWindow = WindowObject,
MUIA_Window_Title, app->app_Title,
MUIA_Window_ID, MAKE_ID('3', 'W', 'I', 'N'),
MUIA_Window_NoMenus, TRUE,
WindowContents, GroupObject,
Child, GroupObject,
MUIA_Background, MUII_BACKGROUND,
MUIA_Frame, MUIV_Frame_Group,
Child, TextObject,
MUIA_Background, MUII_TextBack,
MUIA_Frame, MUIV_Frame_Text,
MUIA_Text_Contents, app->app_Texts[MKDIR_PROMPT],
MUIA_Text_SetMin, TRUE,
MUIA_Text_PreParse, "\33c",
End,
Child, GroupObject,
MUIA_Group_Horiz, TRUE,
Child, HVSpace,
Child, GroupObject,
MUIA_Group_Columns, 2,
Child, Label2(app->app_Texts[MKDIR_INFO]),
Child, CM_mkdir_info = CheckMark(FALSE),
End,
Child, HVSpace,
End,
Child, GroupObject,
MUIA_Group_Columns, 2,
Child, Label2(app->app_Texts[MKDIR_ASKNAME]),
Child, app->app_MkdirName = ST_mkdir_name = StringObject,
MUIA_Frame, MUIV_Frame_String,
End,
End,
End,
Child, GroupObject,
MUIA_Group_Horiz, TRUE,
Child, BT_mkdir_proceed = SimpleButton(app->app_Texts[OK]),
Child, BT_mkdir_cancel = SimpleButton(app->app_Texts[BUTTON_CANCEL]),
End,
End,
End,
// the window for showing the copy-gauge
SubWindow, app->app_GaugeWindow = WindowObject,
MUIA_Window_ID, MAKE_ID('4', 'W', 'I', 'N'),
MUIA_Window_CloseGadget, FALSE,
MUIA_Window_Width, MUIV_Window_Width_Visible(50),
WindowContents, GroupObject,
Child, GroupObject,
MUIA_Background, MUII_BACKGROUND,
MUIA_Frame, MUIV_Frame_Group,
Child, HVSpace,
Child, app->app_GaugeSrc = TextObject,
MUIA_Background, MUII_TextBack,
MUIA_Frame, MUIV_Frame_Text,
MUIA_FrameTitle, app->app_Texts[SOURCEFILE],
MUIA_Text_Contents, NULL,
MUIA_Text_SetMin, TRUE,
End,
Child, app->app_GaugeDest = TextObject,
MUIA_Background, MUII_TextBack,
MUIA_Frame, MUIV_Frame_Text,
MUIA_FrameTitle, app->app_Texts[DESTFILE],
MUIA_Text_Contents, NULL,
MUIA_Text_SetMin, TRUE,
End,
Child, HVSpace,
Child, app->app_GaugeGauge = GaugeObject,
GaugeFrame,
MUIA_FixHeight, 10,
MUIA_Gauge_Horiz, TRUE,
MUIA_Gauge_Max, 100,
End,
Child, ScaleObject,
MUIA_Scale_Horiz, TRUE,
End,
Child, HVSpace,
End,
End,
End,
// this is the main installer window
SubWindow, app->app_MainWindow = WindowObject,
MUIA_Window_Title, app->app_Title,
MUIA_Window_ScreenTitle, app->app_Title,
MUIA_Window_ID, MAKE_ID('0','W','I','N'),
WindowContents, VGroup,
Child, app->app_MainRoot = VGroup,
MUIA_Frame, MUIV_Frame_Group,
MUIA_Background, MUII_RegisterBack,
Child, app->app_CurrentObject = VGroup,
Child, HVSpace,
Child, TextObject,
MUIA_Frame, MUIV_Frame_None,
MUIA_Text_Contents, app->app_Texts[WELCOME],
MUIA_Text_SetMin, TRUE,
MUIA_Text_PreParse, "\33c",
End,
Child, app->app_ParseGauge = GaugeObject,
GaugeFrame,
MUIA_Gauge_Horiz, TRUE,
MUIA_Gauge_InfoText, "%ld %%",
MUIA_Gauge_Max, 100,
End,
Child, HVSpace,
End,
End,
Child, HGroup,
MUIA_Group_Columns, 2,
Child, app->app_ButtonProceed = BT_proceed = SimpleButton((char *) app->app_GlobalEnv[GENV_PROCEED_BUTTON]),
Child, app->app_ButtonCancel = BT_abort = SimpleButton((char *) app->app_GlobalEnv[GENV_ABORT_BUTTON]),
Child, BT_openabout = SimpleButton(app->app_Texts[BUTTON_ABOUT]),
Child, BT_openhelp = SimpleButton(app->app_Texts[BUTTON_HELP]),
End,
End,
End,
End;
if (app->app_Application)
{
// join the different mui objects, such that they communicate
// via notifies
DoMethod(app->app_MainWindow, MUIM_Notify, MUIA_Window_CloseRequest, TRUE,
MUIV_Notify_Self, 2, MUIM_CallHook, &gui_bt_closewin_hook);
//
DoMethod(BT_proceed, MUIM_Notify, MUIA_Pressed, FALSE,
MUIV_Notify_Self, 2, MUIM_CallHook, &gui_bt_proceed_hook);
DoMethod(BT_abort, MUIM_Notify, MUIA_Pressed, FALSE,
MUIV_Notify_Self, 2, MUIM_CallHook, &gui_bt_abort_hook);
//
DoMethod(BT_openabout, MUIM_Notify, MUIA_Pressed, FALSE,
WI_about, 3, MUIM_Set, MUIA_Window_Open, TRUE);
DoMethod(BT_endabout, MUIM_Notify, MUIA_Pressed, FALSE,
WI_about, 3, MUIM_Set, MUIA_Window_Open, FALSE);
DoMethod(WI_about, MUIM_Notify, MUIA_Window_CloseRequest, TRUE,
MUIV_Notify_Self, 3, MUIM_Set, MUIA_Window_Open, FALSE);
//
DoMethod(BT_openhelp, MUIM_Notify, MUIA_Pressed, FALSE,
WI_help, 3, MUIM_Set, MUIA_Window_Open, TRUE);
DoMethod(BT_endhelp, MUIM_Notify, MUIA_Pressed, FALSE,
WI_help, 3, MUIM_Set, MUIA_Window_Open, FALSE);
DoMethod(WI_help, MUIM_Notify, MUIA_Window_CloseRequest, TRUE,
MUIV_Notify_Self, 3, MUIM_Set, MUIA_Window_Open, FALSE);
//
DoMethod(BT_mkdir_cancel, MUIM_Notify, MUIA_Pressed, FALSE,
app->app_MkdirWindow, 3, MUIM_Set, MUIA_Window_Open, FALSE);
DoMethod(BT_mkdir_cancel, MUIM_Notify, MUIA_Pressed, FALSE,
app->app_MainWindow, 3, MUIM_Set, MUIA_Window_Sleep, FALSE);
DoMethod(app->app_MkdirWindow, MUIM_Notify, MUIA_Window_CloseRequest, TRUE,
app->app_MkdirWindow, 3, MUIM_Set, MUIA_Window_Open, FALSE);
DoMethod(app->app_MkdirWindow, MUIM_Notify, MUIA_Window_CloseRequest, TRUE,
app->app_MainWindow, 3, MUIM_Set, MUIA_Window_Sleep, FALSE);
DoMethod(BT_mkdir_proceed, MUIM_Notify, MUIA_Pressed, FALSE,
app->app_MainWindow, 5, MUIM_CallHook, &gui_bt_mkdirproceed_hook, ST_mkdir_name, CM_mkdir_info, app);
//
DoMethod(MN_about, MUIM_Notify, MUIA_Menuitem_Trigger, MUIV_EveryTime,
WI_about, 3, MUIM_Set, MUIA_Window_Open, TRUE);
DoMethod(MN_aboutmui, MUIM_Notify, MUIA_Menuitem_Trigger, MUIV_EveryTime,
WI_aboutmui, 3, MUIM_Set, MUIA_Window_Open, TRUE);
DoMethod(MN_quit, MUIM_Notify, MUIA_Menuitem_Trigger, MUIV_EveryTime,
MUIV_Notify_Self, 2, MUIM_CallHook, &gui_bt_closewin_hook);
//
DoMethod(WI_aboutmui, MUIM_Notify, MUIA_Window_CloseRequest, TRUE,
MUIV_Notify_Self, 3, MUIM_Set, MUIA_Window_Open, FALSE);
//
set(app->app_MainWindow, MUIA_Window_Open, TRUE);
// sleep
guistuff_SleepApp(app);
// done
return (app);
}
}
}
// an error has occured, so we have to free all allocated resources
igui_FreeApp(app);
return (NULL);
}
}
/********************************************************************/
static void __saveds gui_SendCtrlCFun(void) { Signal(FindTask(NULL), SIGBREAKF_CTRL_C); }
static void __saveds gui_SendCtrlDFun(void) { Signal(FindTask(NULL), SIGBREAKF_CTRL_D); }
static void __saveds gui_SendCtrlEFun(void) { Signal(FindTask(NULL), SIGBREAKF_CTRL_E); }
static void __asm __saveds gui_BTMKDirProceedFun(register __a2 APTR obj, register __a1 LONG *data)
{
struct Application *app = (struct Application *) data[2];
long path, icon;
GetAttr(MUIA_String_Contents, (APTR) data[0], (ULONG *) &path); // inhalt des string
GetAttr(MUIA_Selected, (APTR) data[1], (ULONG *) &icon);
// create the new directory
{
BPTR newdir = sav_MakeDir((char *) path);
if (newdir)
{
UnLock(newdir);
// do wee need to create an icon for the new drawer?
if (icon)
{
struct DiskObject *drawer_obj = GetDefDiskObject(WBDRAWER);
if (drawer_obj)
{
PutDiskObject((STRPTR) path, drawer_obj);
FreeDiskObject(drawer_obj);
}
else { /* unable to create the icon, but that doesn't matter */ }
}
}
else { /* failed to create the new directory */ DisplayBeep(NULL); }
}
// done... so cleanup
set(app->app_MainWindow, MUIA_Window_Sleep, FALSE);
set(app->app_MkdirWindow, MUIA_Window_Open, FALSE);
set(app->app_MkdirRelatedDirlist, MUIA_Dirlist_Directory, path);
}